import React, { useImperativeHandle } from "react";
import { Form, Input } from 'antd';
import type { IOuterFilterProps } from "@yaf/pro-ui";

export const Filter: IOuterFilterProps["FilterContent"] = React.forwardRef(({ }, actionRef) => {
  const [form] = Form.useForm();

  useImperativeHandle(actionRef, () => ({
    getFormData: () => new Promise((resolve, reject) => {
      form.validateFields().then((data) => {
        resolve(data);
      }).catch(() => {
        reject(new Error("请检查参数"));
      });
    })
  }));

  return (
    <Form layout="inline" form={form}>
      <Form.Item label="名称" name="name">
        <Input />
      </Form.Item>
    </Form>
  )
});

// 更多过滤条件
export const MoreFilter: IOuterFilterProps["FilterContent"] = React.forwardRef(({ }, actionRef) => {
  const [form] = Form.useForm();

  useImperativeHandle(actionRef, () => ({
    getFormData: () => new Promise((resolve, reject) => {
      form.validateFields().then((data) => {
        resolve(data);
      }).catch(() => {
        reject(new Error("请检查参数"));
      });
    })
  }));

  return (
    <Form layout="horizontal" form={form}>
      <Form.Item label="年龄" name="age">
        <Input />
      </Form.Item>
    </Form>
  )
});
